Setup plotly offline

If you’ve purchased plotly offline, you should’ve received a private download link to a zip file named plotlyjs.zip. Once downloaded, just move that file to your ~/.plotly directory.

if (!dir.exists("~/.plotly")) dir.create("~/.plotly")
file.rename("~/Downloads/plotlyjs.zip", "~/.plotly/plotlyjs.zip")

If, for some reason, you can’t move the zip file to that location, you can tell R to look elsewhere by changing the “plotly_offline” environment variable (in this case, you may want to place this snippet in your ~/.Rprofile).

Sys.setenv("plotly_offline" = "~/Downloads/")

Hello Plotly Offline

To make offline plots, just give the offline() function a plotly object.

library(plotly)
p <- plot_ly(data = iris, x = Sepal.Width, y = Sepal.Length, color = Species,
  mode = "markers")
offline(p)
Drawing…

Or give it a ggplot2 object

gg <- qplot(data = iris, x = Sepal.Width, y = Sepal.Length, color = Species)
offline(gg)
Drawing…

Since plotly offline allows us to make standalone web pages, when using RStudio, your offline plots will appear directly in the viewer:

If you use plotly inside of shiny apps or reactive rmarkdown documents (and have plotly offline), your plotly graphs will be offline by default!

shiny::runApp(system.file("examples/UN_Simple", package = "plotly"))